const is = (value: unknown, type: string) => {
  return Object.prototype.toString.call(value) === `[object ${type}]`;
};

export const isNumber = (value: unknown) => {
  return is(value, "Number");
};

export const isString = (value: unknown) => {
  return is(value, "String");
};

export const isBoolean = (value: unknown) => {
  return is(value, "Boolean");
};

export const isNull = (value: unknown) => {
  return is(value, "Null");
};

export const isUndefined = (value: unknown) => {
  return is(value, "Undefined");
};

export const isSymbol = (value: unknown) => {
  return is(value, "Symbol");
};

export const isBigInt = (value: unknown) => {
  return is(value, "BigInt");
};

export const isObject = (value: unknown) => {
  return is(value, "Object");
};

export const isArray = (value: unknown) => {
  return is(value, "Array");
};

export const isFunction = (value: unknown) => {
  return is(value, "Function");
};

export const isDate = (value: unknown) => {
  return is(value, "Date");
};

export const isRegExp = (value: unknown) => {
  return is(value, "RegExp");
};

export const isPromise = (value: unknown) => {
  return is(value, "Promise");
};

export const isSet = (value: unknown) => {
  return is(value, "Set");
};

export const isMap = (value: unknown) => {
  return is(value, "Map");
};

export const isFile = (value: unknown) => {
  return is(value, "File");
};

/** 空数组 | 空字符串 | 空对象 | 空Map | 空Set */
export const isEmpty = (val: any) => {
  if (!val) return true;

  if (isArray(val) || isString(val)) {
    return val.length === 0;
  }

  if (val instanceof Map || val instanceof Set) {
    return val.size === 0;
  }

  if (isObject(val)) {
    return Object.keys(val).length === 0;
  }

  return true;
};
